﻿using System;
using System.Collections.Generic;
using System.Text;

namespace LibRTC.Core
{
    class RtcClientErrorMap
    {
        //////////////////////////////////////////////////////////////////////
        //																	//
        //////////////////////////////////////////////////////////////////////

        public RtcClientErrorMap(System.Int32 errorCode, string errorCodeText, string errorMessageText)
        {
            this.errorCode = errorCode;
            this.errorCodeText = errorCodeText;
            this.errorMessageText = errorMessageText;
        }

        public System.Int32 errorCode;
        public string errorCodeText;
        public string errorMessageText;
    };

    public class RtcClientErrorTranslator
    {
        //////////////////////////////////////////////////////////////////////
        //	All this better implemented with a hash table, but this code	//
        //	is meant to mirror the C/C++ code for clarity, and building		//
        //	hash tables (maps) with the likes of STL is too '90s.			//
        //																	//
        //	Later, the hashtable is built for more efficient lookups.		//
        //////////////////////////////////////////////////////////////////////

        private static System.Collections.Hashtable rtcClientErrorTranslatorHashtable = null;

        private static RtcClientErrorMap[] rtcClientErrorMap =
            {	
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_CODECS_DO_NOT_MATCH,							"RTC_E_SIP_CODECS_DO_NOT_MATCH",						"No matching codecs with peer"																	),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_STREAM_PRESENT,								"RTC_E_SIP_STREAM_PRESENT",								"The stream to be started is already present"													),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_STREAM_NOT_PRESENT,							"RTC_E_SIP_STREAM_NOT_PRESENT",							"The stream to be stopped is not present"														),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_NO_STREAM,										"RTC_E_SIP_NO_STREAM",									"No stream is active"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_PARSE_FAILED,									"RTC_E_SIP_PARSE_FAILED",								"Parsing SIP failed"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_HEADER_NOT_PRESENT,							"RTC_E_SIP_HEADER_NOT_PRESENT",							"The SIP header is not present in the message"													),
                new RtcClientErrorMap(	RTCConst.RTC_E_SDP_NOT_PRESENT,									"RTC_E_SDP_NOT_PRESENT",								"SDP is not present in the SIP message"															),
                new RtcClientErrorMap(	RTCConst.RTC_E_SDP_PARSE_FAILED,									"RTC_E_SDP_PARSE_FAILED",								"Parsing SDP failed"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_SDP_UPDATE_FAILED,									"RTC_E_SDP_UPDATE_FAILED",								"SDP does not match the previous one"															),
                new RtcClientErrorMap(	RTCConst.RTC_E_SDP_MULTICAST,										"RTC_E_SDP_MULTICAST",									"Multicast is not supported"																	),
                new RtcClientErrorMap(	RTCConst.RTC_E_SDP_CONNECTION_ADDR,								"RTC_E_SDP_CONNECTION_ADDR",							"Media does not contain connection address"														),
                new RtcClientErrorMap(	RTCConst.RTC_E_SDP_NO_MEDIA,										"RTC_E_SDP_NO_MEDIA",									"No media is available for the session"															),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_TIMEOUT,										"RTC_E_SIP_TIMEOUT",									"SIP Transaction timed out"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_SDP_FAILED_TO_BUILD,								"RTC_E_SDP_FAILED_TO_BUILD",							"Failed to build SDP blob"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_INVITE_TRANSACTION_PENDING,					"RTC_E_SIP_INVITE_TRANSACTION_PENDING",					"Currently processing another INVITE transaction"												),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_AUTH_HEADER_SENT,								"RTC_E_SIP_AUTH_HEADER_SENT",							"Authorization header was sent in a previous request"											),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_AUTH_TYPE_NOT_SUPPORTED,						"RTC_E_SIP_AUTH_TYPE_NOT_SUPPORTED",					"The Authentication type requested is not supported"											),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_AUTH_FAILED,									"RTC_E_SIP_AUTH_FAILED",								"Authentication failed"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_INVALID_SIP_URL,									"RTC_E_INVALID_SIP_URL",								"The SIP URL is not valid"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_DESTINATION_ADDRESS_LOCAL,							"RTC_E_DESTINATION_ADDRESS_LOCAL",						"The destination address belongs to the local machine"											),
                new RtcClientErrorMap(	RTCConst.RTC_E_INVALID_ADDRESS_LOCAL,								"RTC_E_INVALID_ADDRESS_LOCAL",							"The Local Address is invalid, check the profile"												),
                new RtcClientErrorMap(	RTCConst.RTC_E_DESTINATION_ADDRESS_MULTICAST,						"RTC_E_DESTINATION_ADDRESS_MULTICAST",					"The destination address is a multicast address"												),
                new RtcClientErrorMap(	RTCConst.RTC_E_INVALID_PROXY_ADDRESS,								"RTC_E_INVALID_PROXY_ADDRESS",							"The proxy address is not valid"																),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_TRANSPORT_NOT_SUPPORTED,						"RTC_E_SIP_TRANSPORT_NOT_SUPPORTED",					"The Transport specified is not supported"														),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_NEED_MORE_DATA,								"RTC_E_SIP_NEED_MORE_DATA",								"Need more data for parsing a whole SIP message"												),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_CALL_DISCONNECTED,								"RTC_E_SIP_CALL_DISCONNECTED",							"The call has been disconnected"																),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_REQUEST_DESTINATION_ADDR_NOT_PRESENT,			"RTC_E_SIP_REQUEST_DESTINATION_ADDR_NOT_PRESENT",		"The Request destination address is not known"													),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_UDP_SIZE_EXCEEDED,								"RTC_E_SIP_UDP_SIZE_EXCEEDED",							"The SIP message size is greater than the UDP message size allowed"								),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_SSL_TUNNEL_FAILED,								"RTC_E_SIP_SSL_TUNNEL_FAILED",							"Cannot establish SSL tunnel to HTTP proxy"														),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_SSL_NEGOTIATION_TIMEOUT,						"RTC_E_SIP_SSL_NEGOTIATION_TIMEOUT",					"Timeout during SSL Negotiation"																),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_STACK_SHUTDOWN,								"RTC_E_SIP_STACK_SHUTDOWN",								"SIP Stack is already shutdown"																	),
                new RtcClientErrorMap(	RTCConst.RTC_E_MEDIA_CONTROLLER_STATE,							"RTC_E_MEDIA_CONTROLLER_STATE",							"Operation not allowed in current media controller state"										),
                new RtcClientErrorMap(	RTCConst.RTC_E_MEDIA_NEED_TERMINAL,								"RTC_E_MEDIA_NEED_TERMINAL",							"Can not find device"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_MEDIA_AUDIO_DEVICE_NOT_AVAILABLE,					"RTC_E_MEDIA_AUDIO_DEVICE_NOT_AVAILABLE",				"Audio device is not available"																	),
                new RtcClientErrorMap(	RTCConst.RTC_E_MEDIA_VIDEO_DEVICE_NOT_AVAILABLE,					"RTC_E_MEDIA_VIDEO_DEVICE_NOT_AVAILABLE",				"Video device is not available"																	),
                new RtcClientErrorMap(	RTCConst.RTC_E_START_STREAM,										"RTC_E_START_STREAM",									"Can not start stream"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_MEDIA_AEC,											"RTC_E_MEDIA_AEC",										"Failed to enable acoustic echo cancellation"													),
                new RtcClientErrorMap(	RTCConst.RTC_E_CLIENT_NOT_INITIALIZED,							"RTC_E_CLIENT_NOT_INITIALIZED",							"Client not initialized"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_CLIENT_ALREADY_INITIALIZED,						"RTC_E_CLIENT_ALREADY_INITIALIZED",						"Client already initialized"																	),
                new RtcClientErrorMap(	RTCConst.RTC_E_CLIENT_ALREADY_SHUT_DOWN,							"RTC_E_CLIENT_ALREADY_SHUT_DOWN",						"Client already shut down"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_PRESENCE_NOT_ENABLED,								"RTC_E_PRESENCE_NOT_ENABLED",							"Presence not enabled"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_INVALID_SESSION_TYPE,								"RTC_E_INVALID_SESSION_TYPE",							"Invalid session type"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_INVALID_SESSION_STATE,								"RTC_E_INVALID_SESSION_STATE",							"Invalid session state"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_NO_PROFILE,										"RTC_E_NO_PROFILE",										"No valid profile for this operation"															),
                new RtcClientErrorMap(	RTCConst.RTC_E_LOCAL_PHONE_NEEDED,								"RTC_E_LOCAL_PHONE_NEEDED",								"A local phone number is needed"																),
                new RtcClientErrorMap(	RTCConst.RTC_E_NO_DEVICE,											"RTC_E_NO_DEVICE",										"No preferred device"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_INVALID_PROFILE,									"RTC_E_INVALID_PROFILE",								"Invalid profile"																				),
                new RtcClientErrorMap(	RTCConst.RTC_E_PROFILE_NO_PROVISION,								"RTC_E_PROFILE_NO_PROVISION",							"No provision tag in profile"																	),
                new RtcClientErrorMap(	RTCConst.RTC_E_PROFILE_NO_KEY,									"RTC_E_PROFILE_NO_KEY",									"No profile key"																				),
                new RtcClientErrorMap(	RTCConst.RTC_E_PROFILE_NO_NAME,									"RTC_E_PROFILE_NO_NAME",								"No profile name"																				),
                new RtcClientErrorMap(	RTCConst.RTC_E_PROFILE_NO_USER,									"RTC_E_PROFILE_NO_USER",								"No user tag in profile"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_PROFILE_NO_USER_URI,								"RTC_E_PROFILE_NO_USER_URI",							"No user URI in profile"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_PROFILE_NO_SERVER,									"RTC_E_PROFILE_NO_SERVER",								"No server tag in profile"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_PROFILE_NO_SERVER_ADDRESS,							"RTC_E_PROFILE_NO_SERVER_ADDRESS",						"Server tag missing address in profile"															),
                new RtcClientErrorMap(	RTCConst.RTC_E_PROFILE_NO_SERVER_PROTOCOL,						"RTC_E_PROFILE_NO_SERVER_PROTOCOL",						"Server tag missing protocol in profile"														),
                new RtcClientErrorMap(	RTCConst.RTC_E_PROFILE_INVALID_SERVER_PROTOCOL,					"RTC_E_PROFILE_INVALID_SERVER_PROTOCOL",				"Invalid server protocol in profile"															),
                new RtcClientErrorMap(	RTCConst.RTC_E_PROFILE_INVALID_SERVER_AUTHMETHOD,					"RTC_E_PROFILE_INVALID_SERVER_AUTHMETHOD",				"Invalid server authentication method in profile"												),
                new RtcClientErrorMap(	RTCConst.RTC_E_PROFILE_INVALID_SERVER_ROLE,						"RTC_E_PROFILE_INVALID_SERVER_ROLE",					"Invalid server role in profile"																),
                new RtcClientErrorMap(	RTCConst.RTC_E_PROFILE_MULTIPLE_REGISTRARS,						"RTC_E_PROFILE_MULTIPLE_REGISTRARS",					"Multiple registrar servers in profile"															),
                new RtcClientErrorMap(	RTCConst.RTC_E_PROFILE_INVALID_SESSION,							"RTC_E_PROFILE_INVALID_SESSION",						"Invalid session tag in profile"																),
                new RtcClientErrorMap(	RTCConst.RTC_E_PROFILE_INVALID_SESSION_PARTY,						"RTC_E_PROFILE_INVALID_SESSION_PARTY",					"Invalid session party in profile"																),
                new RtcClientErrorMap(	RTCConst.RTC_E_PROFILE_INVALID_SESSION_TYPE,						"RTC_E_PROFILE_INVALID_SESSION_TYPE",					"Invalid session type in profile"																),
                new RtcClientErrorMap(	RTCConst.RTC_E_OPERATION_WITH_TOO_MANY_PARTICIPANTS,				"RTC_E_OPERATION_WITH_TOO_MANY_PARTICIPANTS",			"The operation failed because of too many participants in the session"							),
                new RtcClientErrorMap(	RTCConst.RTC_E_BASIC_AUTH_SET_TLS,								"RTC_E_BASIC_AUTH_SET_TLS",								"Must set transport to TLS if Basic Auth is allowed"											),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_HIGH_SECURITY_SET_TLS,							"RTC_E_SIP_HIGH_SECURITY_SET_TLS",						"Must set transport to TLS if high security mode is needed"										),
                new RtcClientErrorMap(	RTCConst.RTC_S_ROAMING_NOT_SUPPORTED,								"RTC_S_ROAMING_NOT_SUPPORTED",							"Server does not support this type of roaming"													),
                new RtcClientErrorMap(	RTCConst.RTC_E_PROFILE_SERVER_UNAUTHORIZED,						"RTC_E_PROFILE_SERVER_UNAUTHORIZED",					"Server address does not match an authorized domain in profile"									),
                new RtcClientErrorMap(	RTCConst.RTC_E_DUPLICATE_REALM,									"RTC_E_DUPLICATE_REALM",								"Duplicate realm exists in an enabled profile"													),
                new RtcClientErrorMap(	RTCConst.RTC_E_POLICY_NOT_ALLOW,									"RTC_E_POLICY_NOT_ALLOW",								"Current policy settings do not allow this action"												),
                new RtcClientErrorMap(	RTCConst.RTC_E_PORT_MAPPING_UNAVAILABLE,							"RTC_E_PORT_MAPPING_UNAVAILABLE",						"Port mapping can not be obtained from the port manager"										),
                new RtcClientErrorMap(	RTCConst.RTC_E_PORT_MAPPING_FAILED,								"RTC_E_PORT_MAPPING_FAILED",							"Port mapping failure returned from the port manager"											),
                new RtcClientErrorMap(	RTCConst.RTC_E_SECURITY_LEVEL_NOT_COMPATIBLE,						"RTC_E_SECURITY_LEVEL_NOT_COMPATIBLE",					"The local and remote security levels are not compatible"										),
                new RtcClientErrorMap(	RTCConst.RTC_E_SECURITY_LEVEL_NOT_DEFINED,						"RTC_E_SECURITY_LEVEL_NOT_DEFINED",						"The security level is not defined"																),
                new RtcClientErrorMap(	RTCConst.RTC_E_SECURITY_LEVEL_NOT_SUPPORTED_BY_PARTICIPANT,		"RTC_E_SECURITY_LEVEL_NOT_SUPPORTED_BY_PARTICIPANT",	"Participant could not support the requested security level"									),
                new RtcClientErrorMap(	RTCConst.RTC_E_DUPLICATE_BUDDY,									"RTC_E_DUPLICATE_BUDDY",								"Buddy already exists"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_DUPLICATE_WATCHER,									"RTC_E_DUPLICATE_WATCHER",								"Watcher already exists"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_MALFORMED_XML,										"RTC_E_MALFORMED_XML",									"Malformed XML"																					),
                new RtcClientErrorMap(	RTCConst.RTC_E_ROAMING_OPERATION_INTERRUPTED,						"RTC_E_ROAMING_OPERATION_INTERRUPTED",					"Roaming operation interrupted. It may succeed or fail"											),
                new RtcClientErrorMap(	RTCConst.RTC_E_ROAMING_FAILED,									"RTC_E_ROAMING_FAILED",									"Roaming session failed"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_INVALID_BUDDY_LIST,								"RTC_E_INVALID_BUDDY_LIST,",							"Buddy list is invalid"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_INVALID_ACL_LIST,									"RTC_E_INVALID_ACL_LIST",								"ACL list is invalid"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_NO_GROUP,											"RTC_E_NO_GROUP",										"Group does not exist"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_DUPLICATE_GROUP,									"RTC_E_DUPLICATE_GROUP",								"Group already exists"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_TOO_MANY_GROUPS,									"RTC_E_TOO_MANY_GROUPS",								"Max number of groups has been reached"															),
                new RtcClientErrorMap(	RTCConst.RTC_E_NO_BUDDY,											"RTC_E_NO_BUDDY",										"Buddy does not exist"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_NO_WATCHER,										"RTC_E_NO_WATCHER",										"Watcher does not exist"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_NO_REALM,											"RTC_E_NO_REALM",										"No realm is set"																				),
                new RtcClientErrorMap(	RTCConst.RTC_E_NO_TRANSPORT,										"RTC_E_NO_TRANSPORT",									"Server can not be specified without a transport protocol"										),
                new RtcClientErrorMap(	RTCConst.RTC_E_NOT_EXIST,											"RTC_E_NOT_EXIST",										"The required item does not exist"																),
                new RtcClientErrorMap(	RTCConst.RTC_E_INVALID_PREFERENCE_LIST,							"RTC_E_INVALID_PREFERENCE_LIST",						"Preference list is invalid"																	),
                new RtcClientErrorMap(	RTCConst.RTC_E_MAX_PENDING_OPERATIONS,							"RTC_E_MAX_PENDING_OPERATIONS",							"Maximum number of pending operations reached"													),
                new RtcClientErrorMap(	RTCConst.RTC_E_TOO_MANY_RETRIES,									"RTC_E_TOO_MANY_RETRIES",								"Too many attempts to resend a request"															),
                new RtcClientErrorMap(	RTCConst.RTC_E_INVALID_PORTRANGE,									"RTC_E_INVALID_PORTRANGE,",								"Invalid port range"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_CALL_CONNECTION_NOT_ESTABLISHED,				"RTC_E_SIP_CALL_CONNECTION_NOT_ESTABLISHED",			"Call connection has not been established"														),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_ADDITIONAL_PARTY_IN_TWO_PARTY_SESSION,			"RTC_E_SIP_ADDITIONAL_PARTY_IN_TWO_PARTY_SESSION",		"Adding additional parties to two party session failed"											),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_PARTY_ALREADY_IN_SESSION,						"RTC_E_SIP_PARTY_ALREADY_IN_SESSION",					"Party already exists in session"																),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_OTHER_PARTY_JOIN_IN_PROGRESS,					"RTC_E_SIP_OTHER_PARTY_JOIN_IN_PROGRESS",				"Join operation is in progress for another party"												),
                new RtcClientErrorMap(	RTCConst.RTC_E_INVALID_OBJECT_STATE,								"RTC_E_INVALID_OBJECT_STATE",							"Object state does not allow to perform this operation"											),
                new RtcClientErrorMap(	RTCConst.RTC_E_PRESENCE_ENABLED,									"RTC_E_PRESENCE_ENABLED",								"Presence is enabled"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_ROAMING_ENABLED,									"RTC_E_ROAMING_ENABLED",								"Roaming is enabled"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_TLS_INCOMPATIBLE_ENCRYPTION,					"RTC_E_SIP_TLS_INCOMPATIBLE_ENCRYPTION",				"Incompatible TLS encryption"																	),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_INVALID_CERTIFICATE,							"RTC_E_SIP_INVALID_CERTIFICATE",						"Invalid certificate"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_DNS_FAIL,										"RTC_E_SIP_DNS_FAIL",									"DNS lookup fails"																				),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_TCP_FAIL,										"RTC_E_SIP_TCP_FAIL",									"Fails to make a TCP connection"																),
                new RtcClientErrorMap(	RTCConst.RTC_E_TOO_SMALL_EXPIRES_VALUE,							"RTC_E_TOO_SMALL_EXPIRES_VALUE",						"Expires value received from the server is too small"											),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_TLS_FAIL,										"RTC_E_SIP_TLS_FAIL,",									"Fails to make a TLS connection"																),
                new RtcClientErrorMap(	RTCConst.RTC_E_NOT_PRESENCE_PROFILE,								"RTC_E_NOT_PRESENCE_PROFILE",							"A presence profile must be used"																),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_INVITEE_PARTY_TIMEOUT,							"RTC_E_SIP_INVITEE_PARTY_TIMEOUT",						"Invitee connection fails"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_AUTH_TIME_SKEW,								"RTC_E_SIP_AUTH_TIME_SKEW",								"Authentication failure because of time skew between client and server"							),
                new RtcClientErrorMap(	RTCConst.RTC_E_INVALID_REGISTRATION_STATE,						"RTC_E_INVALID_REGISTRATION_STATE",						"Invalid registration state"																	),
                new RtcClientErrorMap(	RTCConst.RTC_E_MEDIA_DISABLED,									"RTC_E_MEDIA_DISABLED",									"Media is disabled"																				),
                new RtcClientErrorMap(	RTCConst.RTC_E_MEDIA_ENABLED,										"RTC_E_MEDIA_ENABLED",									"Media is enabled"																				),
                new RtcClientErrorMap(	RTCConst.RTC_E_REFER_NOT_ACCEPTED,								"RTC_E_REFER_NOT_ACCEPTED",								"Refer has not been accepted"																	),
                new RtcClientErrorMap(	RTCConst.RTC_E_REFER_NOT_ALLOWED,									"RTC_E_REFER_NOT_ALLOWED",								"Refer operation is not allowed in this session"												),
                new RtcClientErrorMap(	RTCConst.RTC_E_REFER_NOT_EXIST,									"RTC_E_REFER_NOT_EXIST",								"Refer session does not exist or has finished"													),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_HOLD_OPERATION_PENDING,						"RTC_E_SIP_HOLD_OPERATION_PENDING",						"Currently an hold operation is pending"														),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_UNHOLD_OPERATION_PENDING,						"RTC_E_SIP_UNHOLD_OPERATION_PENDING",					"Currently an unhold operation is pending"														),
                new RtcClientErrorMap(	RTCConst.RTC_E_MEDIA_SESSION_NOT_EXIST,							"RTC_E_MEDIA_SESSION_NOT_EXIST",						"Media session does not exist"																	),
                new RtcClientErrorMap(	RTCConst.RTC_E_MEDIA_SESSION_IN_HOLD,								"RTC_E_MEDIA_SESSION_IN_HOLD",							"Media session is in hold"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_ANOTHER_MEDIA_SESSION_ACTIVE,						"RTC_E_ANOTHER_MEDIA_SESSION_ACTIVE",					"Another media session is active"																),
                new RtcClientErrorMap(	RTCConst.RTC_E_MAX_REDIRECTS,										"RTC_E_MAX_REDIRECTS",									"Too many redirects"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_REDIRECT_PROCESSING_FAILED,						"RTC_E_REDIRECT_PROCESSING_FAILED",						"Processing redirect failed"																	),
                new RtcClientErrorMap(	RTCConst.RTC_E_LISTENING_SOCKET_NOT_EXIST,						"RTC_E_LISTENING_SOCKET_NOT_EXIST",						"Listening socket does not exist"																),
                new RtcClientErrorMap(	RTCConst.RTC_E_INVALID_LISTEN_SOCKET,								"RTC_E_INVALID_LISTEN_SOCKET",							"Specified address and port is invalid"															),
                new RtcClientErrorMap(	RTCConst.RTC_E_PORT_MANAGER_ALREADY_SET,							"RTC_E_PORT_MANAGER_ALREADY_SET",						"Port manager already set"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_SECURITY_LEVEL_ALREADY_SET,						"RTC_E_SECURITY_LEVEL_ALREADY_SET",						"The security level has already been set for this Media type can and can not be changed"		),
                new RtcClientErrorMap(	RTCConst.RTC_E_UDP_NOT_SUPPORTED,									"RTC_E_UDP_NOT_SUPPORTED",								"This feature is not supported when one of the server in profile has UDP transport"				),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_REFER_OPERATION_PENDING,						"RTC_E_SIP_REFER_OPERATION_PENDING",					"Currently a refer operation is pending"														),
                new RtcClientErrorMap(	RTCConst.RTC_E_PLATFORM_NOT_SUPPORTED,							"RTC_E_PLATFORM_NOT_SUPPORTED",							"This operation is not supported on this Windows Platform."										),
                new RtcClientErrorMap(	RTCConst.RTC_E_SIP_PEER_PARTICIPANT_IN_MULTIPARTY_SESSION,		"RTC_E_SIP_PEER_PARTICIPANT_IN_MULTIPARTY_SESSION",		"A peer participant cannot be added to a multiparty session"									),
                new RtcClientErrorMap(	RTCConst.RTC_E_NOT_ALLOWED,										"RTC_E_NOT_ALLOWED",									"This action is not allowed"																	),
                new RtcClientErrorMap(	RTCConst.RTC_E_REGISTRATION_DEACTIVATED,							"RTC_E_REGISTRATION_DEACTIVATED",						"The user is being moved"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_REGISTRATION_REJECTED,								"RTC_E_REGISTRATION_REJECTED",							"The user's account was disabled or deleted or the SIP URI changed"								),
                new RtcClientErrorMap(	RTCConst.RTC_E_REGISTRATION_UNREGISTERED,							"RTC_E_REGISTRATION_UNREGISTERED",						"The user was logged out because the user logged in elsewhere"									),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_INFO_TRYING,								"RTC_E_STATUS_INFO_TRYING",								"Trying"																						),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_INFO_RINGING,								"RTC_E_STATUS_INFO_RINGING",							"Ringing"																						),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_INFO_CALL_FORWARDING,						"RTC_E_STATUS_INFO_CALL_FORWARDING",					"Call Is Being Forwarded"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_INFO_QUEUED,								"RTC_E_STATUS_INFO_QUEUED",								"Queued"																						),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_SESSION_PROGRESS,							"RTC_E_STATUS_SESSION_PROGRESS",						"Session Progress"																				),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_SUCCESS,									"RTC_E_STATUS_SUCCESS",									"OK"																							),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_REDIRECT_MULTIPLE_CHOICES,					"RTC_E_STATUS_REDIRECT_MULTIPLE_CHOICES",				"Multiple choices"																				),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_REDIRECT_MOVED_PERMANENTLY,					"RTC_E_STATUS_REDIRECT_MOVED_PERMANENTLY",				"Moved permanently"																				),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_REDIRECT_MOVED_TEMPORARILY,					"RTC_E_STATUS_REDIRECT_MOVED_TEMPORARILY",				"Moved temporarily"																				),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_REDIRECT_SEE_OTHER,							"RTC_E_STATUS_REDIRECT_SEE_OTHER",						"See other"																						),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_REDIRECT_USE_PROXY,							"RTC_E_STATUS_REDIRECT_USE_PROXY",						"Use proxy"																						),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_REDIRECT_ALTERNATIVE_SERVICE,				"RTC_E_STATUS_REDIRECT_ALTERNATIVE_SERVICE",			"Alternative service"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_BAD_REQUEST,							"RTC_E_STATUS_CLIENT_BAD_REQUEST",						"Bad request"																					),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_UNAUTHORIZED,						"RTC_E_STATUS_CLIENT_UNAUTHORIZED",						"Unauthorized"																					),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_PAYMENT_REQUIRED,					"RTC_E_STATUS_CLIENT_PAYMENT_REQUIRED",					"Payment required"																				),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_FORBIDDEN,							"RTC_E_STATUS_CLIENT_FORBIDDEN",						"Forbidden"																						),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_NOT_FOUND,							"RTC_E_STATUS_CLIENT_NOT_FOUND",						"Not found"																						),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_METHOD_NOT_ALLOWED,					"RTC_E_STATUS_CLIENT_METHOD_NOT_ALLOWED",				"Method not allowed"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_NOT_ACCEPTABLE,						"RTC_E_STATUS_CLIENT_NOT_ACCEPTABLE",					"Not acceptable"																				),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_PROXY_AUTHENTICATION_REQUIRED,		"RTC_E_STATUS_CLIENT_PROXY_AUTHENTICATION_REQUIRED",	"Proxy authentication required"																	),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_REQUEST_TIMEOUT,						"RTC_E_STATUS_CLIENT_REQUEST_TIMEOUT",					"Timeout"																						),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_CONFLICT,							"RTC_E_STATUS_CLIENT_CONFLICT",							"Conflict"																						),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_GONE,								"RTC_E_STATUS_CLIENT_GONE",								"Gone"																							),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_LENGTH_REQUIRED,						"RTC_E_STATUS_CLIENT_LENGTH_REQUIRED",					"Length required"																				),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_REQUEST_ENTITY_TOO_LARGE,			"RTC_E_STATUS_CLIENT_REQUEST_ENTITY_TOO_LARGE",			"Request entity too large"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_REQUEST_URI_TOO_LARGE,				"RTC_E_STATUS_CLIENT_REQUEST_URI_TOO_LARGE",			"Request-URI too long"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_UNSUPPORTED_MEDIA_TYPE,				"RTC_E_STATUS_CLIENT_UNSUPPORTED_MEDIA_TYPE",			"Unsupported media type"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_BAD_EXTENSION,						"RTC_E_STATUS_CLIENT_BAD_EXTENSION",					"Bad extension"																					),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_TEMPORARILY_NOT_AVAILABLE,			"RTC_E_STATUS_CLIENT_TEMPORARILY_NOT_AVAILABLE",		"Temporarily unavailable"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_TRANSACTION_DOES_NOT_EXIST,			"RTC_E_STATUS_CLIENT_TRANSACTION_DOES_NOT_EXIST",		"Call leg/transaction does not exist"															),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_LOOP_DETECTED,						"RTC_E_STATUS_CLIENT_LOOP_DETECTED",					"Loop detected"																					),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_TOO_MANY_HOPS,						"RTC_E_STATUS_CLIENT_TOO_MANY_HOPS",					"Too many hops"																					),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_ADDRESS_INCOMPLETE,					"RTC_E_STATUS_CLIENT_ADDRESS_INCOMPLETE",				"Address incomplete"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_AMBIGUOUS,							"RTC_E_STATUS_CLIENT_AMBIGUOUS",						"Ambiguous"																						),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_CLIENT_BUSY_HERE,							"RTC_E_STATUS_CLIENT_BUSY_HERE",						"Busy here"																						),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_REQUEST_TERMINATED,							"RTC_E_STATUS_REQUEST_TERMINATED",						"Request terminated"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_NOT_ACCEPTABLE_HERE,						"RTC_E_STATUS_NOT_ACCEPTABLE_HERE",						"Not acceptable here"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_SERVER_INTERNAL_ERROR,						"RTC_E_STATUS_SERVER_INTERNAL_ERROR",					"Server internal error"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_SERVER_NOT_IMPLEMENTED,						"RTC_E_STATUS_SERVER_NOT_IMPLEMENTED",					"Not implemented"																				),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_SERVER_BAD_GATEWAY,							"RTC_E_STATUS_SERVER_BAD_GATEWAY",						"Bad gateway"																					),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_SERVER_SERVICE_UNAVAILABLE,					"RTC_E_STATUS_SERVER_SERVICE_UNAVAILABLE",				"Service unavailable"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_SERVER_SERVER_TIMEOUT,						"RTC_E_STATUS_SERVER_SERVER_TIMEOUT",					"Server timeout"																				),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_SERVER_VERSION_NOT_SUPPORTED,				"RTC_E_STATUS_SERVER_VERSION_NOT_SUPPORTED",			"Not supported"																					),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_GLOBAL_BUSY_EVERYWHERE,						"RTC_E_STATUS_GLOBAL_BUSY_EVERYWHERE",					"Busy everywhere"																				),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_GLOBAL_DECLINE,								"RTC_E_STATUS_GLOBAL_DECLINE",							"Decline"																						),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_GLOBAL_DOES_NOT_EXIST_ANYWHERE,				"RTC_E_STATUS_GLOBAL_DOES_NOT_EXIST_ANYWHERE",			"Does not exist anywhere"																		),
                new RtcClientErrorMap(	RTCConst.RTC_E_STATUS_GLOBAL_NOT_ACCEPTABLE,						"RTC_E_STATUS_GLOBAL_NOT_ACCEPTABLE",					"Not acceptable"																				),
                new RtcClientErrorMap(	RTCConst.RTC_E_PINT_STATUS_REJECTED_BUSY,							"RTC_E_PINT_STATUS_REJECTED_BUSY",						"Busy"																							),
                new RtcClientErrorMap(	RTCConst.RTC_E_PINT_STATUS_REJECTED_NO_ANSWER,					"RTC_E_PINT_STATUS_REJECTED_NO_ANSWER",					"No answer"																						),
                new RtcClientErrorMap(	RTCConst.RTC_E_PINT_STATUS_REJECTED_ALL_BUSY,						"RTC_E_PINT_STATUS_REJECTED_ALL_BUSY",					"All busy"																						),
                new RtcClientErrorMap(	RTCConst.RTC_E_PINT_STATUS_REJECTED_PL_FAILED,					"RTC_E_PINT_STATUS_REJECTED_PL_FAILED",					"Primary leg failed"																			),
                new RtcClientErrorMap(	RTCConst.RTC_E_PINT_STATUS_REJECTED_SW_FAILED,					"RTC_E_PINT_STATUS_REJECTED_SW_FAILED",					"Switch failed"																					),
                new RtcClientErrorMap(	RTCConst.RTC_E_PINT_STATUS_REJECTED_CANCELLED,					"RTC_E_PINT_STATUS_REJECTED_CANCELLED",					"Cancelled"																						),
                new RtcClientErrorMap(	RTCConst.RTC_E_PINT_STATUS_REJECTED_BADNUMBER,					"RTC_E_PINT_STATUS_REJECTED_BADNUMBER",					"Bad number"																					),
            };

        //////////////////////////////////////////////////////////////////////
        //																	//
        //////////////////////////////////////////////////////////////////////
        public static string ToString(System.Int32 hr)
        {
            try
            {
                //	Initalize the hash table (only once)
                if (RtcClientErrorTranslator.rtcClientErrorTranslatorHashtable == null)
                {
                    RtcClientErrorTranslator.rtcClientErrorTranslatorHashtable = new System.Collections.Hashtable(rtcClientErrorMap.Length);

                    for (int i = 0; i < rtcClientErrorMap.Length; i++)
                    {
                        rtcClientErrorTranslatorHashtable.Add(rtcClientErrorMap[i].errorCode, rtcClientErrorMap[i]);
                    }
                }

                string stringBuilder = "";
                System.Int64 maskedHr = 0;

                maskedHr = (hr & 0xC0000000);

                switch (maskedHr)
                {
                    case 0x00000000: stringBuilder += "[ Success ]"; break;
                    case 0x40000000: stringBuilder += "[ Informational ]"; break;
                    case 0x80000000: stringBuilder += "[ Warning ]"; break;
                    case 0xC0000000: stringBuilder += "[ Error ]"; break;
                }

                maskedHr = ((hr & 0x0fff0000) >> 16);

                switch (maskedHr)
                {
                    case RTCConst.FACILITY_SIP_STATUS_CODE: stringBuilder += "[ SIP Status ]"; break;
                    case RTCConst.FACILITY_RTC_INTERFACE: stringBuilder += "[ RTC Interface ]"; break;
                    case RTCConst.FACILITY_PINT_STATUS_CODE: stringBuilder += "[ PINT Status ]"; break;
                }

                //	Find the error text translation

                RtcClientErrorMap rtcCleintErrorMapEntry = (RtcClientErrorMap)rtcClientErrorTranslatorHashtable[hr];

                if (rtcCleintErrorMapEntry != null)
                {
                    stringBuilder += "[ " + rtcCleintErrorMapEntry.errorCodeText + " ]";
                    stringBuilder += "[ 0x" + System.String.Format("{0:X}", rtcCleintErrorMapEntry.errorCode) + " ]";
                    stringBuilder += ": " + rtcCleintErrorMapEntry.errorMessageText;
                }

                return (stringBuilder);
            }
            catch (System.Exception e)
            {
                throw e;
            }
        }
    }
}